<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/**
 * @category   Zead
 * @package    Zead_Player
 * @supackage  Zead_Player_Action
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License 
 */
class Zead_Player_Action
{
	/** @var Zead_Player_Action_Helper */
	protected $_helpers = array();

	/** @var array */
	protected $_helperPaths = array();
	
	/** @var Zead_Player **/
	protected $_player = null;

	/** @var Zend_Controller_Request_Abstract **/
	protected $_request = null;

	/** @var Zend_Controller_Response_Abstract **/
	protected $_response = null;
	
	/**
	 * Class constructor
	 *
	 * @param  Zend_Controller_Request_Abstract $request
	 * @param  Zend_Controller_Response_Abstract $response
	 */
	public function __construct (Zend_Controller_Request_Abstract  $request, Zend_Controller_Response_Abstract $response) 
	{
		$this->_request = $request;
		$this->_response = $response;	
	}

	/**
	 * Set the frontControlller
	 * 
	 * @param  Zead_Player $player
	 * @return Zead_Player_Action
	 */
	public function setPlayer(Zead_Player $player)
	{
		$this->_player = $player;
		return $this;
	}

	/**
	 * Returns the frontController
	 * 
	 * @return Zead_Player
	 */
	public function getPlayer() 
	{
		if (null == $this->_player) {
			require_once 'Zead/Player.php';
			$this->setPlayer(Zead_Player::getInstance());
		}
		
		return $this->_player;
	}
	
	/**
	 * Returns the request object registered to current action/resource
	 * 
	 * @return Zead_Player_Request_Abstract
	 */
	public function getRequest() 
	{
		return $this->_request;	
	}

	/**
	 * Returns the response object registered to currenct action/resource
	 * 
	 * @return Zead_Player_Response_Abstract
	 */
	public function getResponse() 
	{
		return $this->_response;
	}

	/**
	 * Metodo para ser iniciado antes do despacho (completo) do recurso.
	 * @return void
	 */
	public function init() {
	}

	/**
	 * Efetua um pre-despacho antes da acao principal
	 * @return void
	 */
	public function preDispatch() {
	}

	/**
	 * Despachando a ação principal
	 * @return void
	 */
	public function dispatch() {	
	}

	/**
	 * Efetua uma pos-despacho após a execucao da acao principal
	 * @return void
	 */
	public function postDispatch() {
	}
	
	protected function _helper($helperName)
	{
		return $this->_helpers = array($helperName);		
	}

	
	public function __get($attribute)
	{
		if ($attribute == 'manifest') {
			if (null === $this->_helpers['manifest']) {
				require_once 'Zead/Player/Action/Helper/Manifest.php';
				$helper = new Zead_Player_Action_Helper_Manifest($this->getRequest(), $this->getResponse());
				$helper->init();
				$this->_helpers['manifest'] = $helper;	
			}
			return $this->_helpers['manifest'];
		}
	}
}

